package com.shujia.wyh.day21;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
        HashMap嵌套ArrayList
 */
public class HashMapAndArrayList {
    public static void main(String[] args) {
        //创建一个HashMap对象
        HashMap<ArrayList<Student5>, String> map = new HashMap<>();

        //创建ArrayList对象
        ArrayList<Student5> array1 = new ArrayList<>();
        ArrayList<Student5> array2 = new ArrayList<>();
        ArrayList<Student5> array3 = new ArrayList<>();

        //创建学生对象
        Student5 s1 = new Student5("小花", 18);
        Student5 s2 = new Student5("小白", 17);
        Student5 s3 = new Student5("小黑", 16);
        Student5 s4 = new Student5("小小", 19);
        Student5 s5 = new Student5("小蓝", 20);
        Student5 s6 = new Student5("小红", 21);

        //给ArrayList中添加元素
        array1.add(s1);
        array1.add(s2);
        array1.add(s3);

        array2.add(s4);
        array2.add(s5);

        array3.add(s6);

        //将ArrayList作为key存放到map中
        map.put(array1, "普通班");
        map.put(array2, "精英班");
        map.put(array3, "强化班");

        //遍历集合
        Set<Map.Entry<ArrayList<Student5>, String>> entries = map.entrySet();
        for (Map.Entry<ArrayList<Student5>, String> keyValue : entries) {
            ArrayList<Student5> key = keyValue.getKey();
            String value = keyValue.getValue();
            System.out.println(value + "班级学生信息如下：");
            for (Student5 student5 : key) {
                System.out.println(student5);
            }
        }


    }
}
